package br.inf.solutions.apresentacoes.ssp.model.bulletin;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import br.com.vexillum.model.CommonEntityActivated;
import br.com.vexillum.model.annotations.SearchField;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.PostGraduation;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructEntity;
import br.inf.solutions.apresentacoes.ssp.model.interfaces.IExistsPerson;

@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.BulletinValidator")
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"number_bulletin", "year_bulletin"}))
@SuppressWarnings("serial")
public class Bulletin extends CommonEntityActivated implements IExistsPerson {

	public Bulletin() {
		super();
		dateBulletin = new Date();
		yearBulletin = Integer.parseInt(new SimpleDateFormat("yyyy").format(dateBulletin));
	}
	
	@Validate(notNull = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "bulletinType_id", nullable = false, updatable = true, unique = false)
	private BulletinType bulletinType;

	@SearchField
	@Column(name = "number_bulletin")
	private Long numberBulletin;

	@SearchField
	@Column(name = "year_bulletin")
	private Integer yearBulletin;

	@Column(name = "date_bulletin")
	private Date dateBulletin;

	@Validate(notNull=true)
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="person_id",insertable=true, updatable=true, unique=false)
	private Person person;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "post", nullable = true, updatable = true, unique = false)
	private PostGraduation post;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "function", nullable = true, updatable = true, unique = false)
	private HierarchyStructEntity function;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "unity", nullable = true, updatable = true, unique = false)
	private HierarchyStructEntity unity;
	
	private String namePdf;

	public BulletinType getBulletinType() {
		return bulletinType;
	}

	public void setBulletinType(BulletinType bulletinType) {
		this.bulletinType = bulletinType;
	}

	public Long getNumberBulletin() {
		return numberBulletin;
	}

	public void setNumberBulletin(Long numberBulletin) {
		this.numberBulletin = numberBulletin;
	}

	public Integer getYearBulletin() {
		return yearBulletin;
	}

	public void setYearBulletin(Integer yearBulletin) {
		this.yearBulletin = yearBulletin;
	}

	public Date getDateBulletin() {
		return dateBulletin;
	}

	public void setDateBulletin(Date dateBulletin) {
		this.dateBulletin = dateBulletin;
	}

	public HierarchyStructEntity getUnity() {
		return unity;
	}

	public void setUnity(HierarchyStructEntity unity) {
		this.unity = unity;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}
	
	public String getNamePdf() {
		return namePdf;
	}

	public void setNamePdf(String namePdf) {
		this.namePdf = namePdf;
	}

	public PostGraduation getPost() {
		return post;
	}

	public void setPost(PostGraduation post) {
		this.post = post;
	}

	public HierarchyStructEntity getFunction() {
		return function;
	}

	public void setFunction(HierarchyStructEntity function) {
		this.function = function;
	}

	public String getCompleteNumber(){
		return numberBulletin + "/" + yearBulletin;
	}

}
